package com.control;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dominio.Usuario;
import com.jdbc.BDManagement;


public class MostrarRut extends HttpServlet {
	BDManagement bdm = new BDManagement();

    public MostrarRut() {
        super();
    }
    
    protected void rutaService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
    	LinkedList<Usuario> listaDeUsers = new LinkedList<Usuario>();
		ResultSet r = bdm.getAllUsuarios();
		while(r.next()){
			Usuario user = new Usuario(r.getString(2), r.getString(3), r.getString(5), r.getString(6), r.getString(7));
			listaDeUsers.add(user);
		}
		request.setAttribute("listaDeUsers", listaDeUsers);
		this.getServletContext().getRequestDispatcher("/mostrarRutas.jsp").forward(request, response);
	}

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			rutaService(request, response);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			rutaService(request, response);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
